﻿// <copyright file="MouseInputManager.Overlay.cs" company="ThorIndustry">Copyright (c) ThorIndustry. All rights reserved.</copyright>

public partial class MouseInputManager
{
    public UnityEngine.GameObject ButtonPrefab;
    private Button flipButton;

    private void InitializeOverlay()
    {
        // Display the "flip" button.
        float x = 0.5f;

        // Back button.
        UnityEngine.GameObject buttonObject = UnityEngine.GameObject.Instantiate(this.ButtonPrefab) as UnityEngine.GameObject;
        this.flipButton = buttonObject.GetComponent<Button>();
        this.flipButton.IsVisible = false;
        this.flipButton.Clicked += this.FlipButtonClicked;

        // Place the button.
        UnityEngine.Transform buttonTransform = this.flipButton.transform;
        buttonTransform.parent = this.transform;

        this.flipButton.GuiText.text = "Flip";

        UnityEngine.Rect rect = GuiHelper.FormatGuiTextArea(this.flipButton.GuiText, 300 * GuiHelper.GetScreenSizeRatio());
        rect.height = 50 * GuiHelper.GetScreenSizeRatio();
        rect.width = UnityEngine.Mathf.Max((75 * GuiHelper.GetScreenSizeRatio()), rect.width + (10 * GuiHelper.GetScreenSizeRatio()));
        rect.x = -rect.width / 2;
        rect.y = -rect.height / 2;
        this.flipButton.GuiTexture.pixelInset = rect;

        float y = 1 - ((rect.height + (5 * GuiHelper.GetScreenSizeRatio())) / UnityEngine.Screen.height);
        buttonTransform.localPosition = new UnityEngine.Vector3(x, y, 0);

        this.flipButton.GuiText.pixelOffset = new UnityEngine.Vector2(0, 0);
    }

    private void ShowOverlay()
    {
        this.flipButton.IsVisible = true;
        this.flipButton.gameObject.SetActive(true);
    }

    private void HideOverlay()
    {
        this.flipButton.IsVisible = false;
        this.flipButton.gameObject.SetActive(false);
    }

    private void ChangeFlipButtonEnable(bool enable)
    {
        this.flipButton.Enable(enable);
    }

    private void FlipButtonClicked(object sender, System.EventArgs args)
    {
        this.FlipSelectedShape();
    }

    private bool IsMouseOverButtons()
    {
        if (this.flipButton.HitTest(UnityEngine.Input.mousePosition))
        {
            return true;
        }

        return false;
    }
}
